// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso.sprite;

public final class IsoSpriteGrid {
    private IsoSprite[] sprites;
    private int width;
    private int height;

    public IsoSpriteGrid(int w, int h) {
        this.sprites = new IsoSprite[w * h];
        this.width = w;
        this.height = h;
    }

    public IsoSprite getAnchorSprite() {
        return this.sprites.length > 0 ? this.sprites[0] : null;
    }

    public IsoSprite getSprite(int x, int y) {
        return this.getSpriteFromIndex(y * this.width + x);
    }

    public void setSprite(int x, int y, IsoSprite sprite) {
        this.sprites[y * this.width + x] = sprite;
    }

    public int getSpriteIndex(IsoSprite sprite) {
        for (int _int = 0; _int < this.sprites.length; _int++) {
            IsoSprite isoSprite = this.sprites[_int];
            if (isoSprite != null && isoSprite == sprite) {
                return _int;
            }
        }

        return -1;
    }

    public int getSpriteGridPosX(IsoSprite sprite) {
        int _int = this.getSpriteIndex(sprite);
        return _int >= 0 ? _int % this.width : -1;
    }

    public int getSpriteGridPosY(IsoSprite sprite) {
        int _int = this.getSpriteIndex(sprite);
        return _int >= 0 ? _int / this.width : -1;
    }

    public IsoSprite getSpriteFromIndex(int index) {
        return index >= 0 && index < this.sprites.length ? this.sprites[index] : null;
    }

    public int getWidth() {
        return this.width;
    }

    public int getHeight() {
        return this.height;
    }

    public boolean validate() {
        for (int _int = 0; _int < this.sprites.length; _int++) {
            if (this.sprites[_int] == null) {
                return false;
            }
        }

        return true;
    }

    public int getSpriteCount() {
        return this.sprites.length;
    }

    public IsoSprite[] getSprites() {
        return this.sprites;
    }
}
